<template>
	<q-popup v-model="show">
		<view class="popup-content d-flex flex-column">
			<view class="d-flex justify-content-end">
				<u-icon class="text-color-grey" name="close" size="40" @tap="close"></u-icon>
			</view>
			<view class="d-flex flex-fill flex-column justify-content-between">
				<view class="d-flex flex-column">
					<view class="font-size-extra-lg font-weight-bold text-color-base mb-30">欢迎登陆人人约拍~</view>
					<view class="font-size-base text-color-assist">人人约拍是一个商家、模特和摄影师拍摄作品、买家秀、种草视频的约拍服务商！</view>
				</view>
				<view class="d-flex flex-column">
					<button type="primary" class="w-100 font-size-lg mb-30" @tap="login">微信一键登陆</button>
					<view class="text-center mb-30 font-size-sm text-color-assist">
						登陆即表示已阅读并同意<font class="text-color-primary" @tap="jump('/pages/user/user-agreement')">《用户协议》</font>与<font class="text-color-primary" @tap="jump('/pages/user/privacy-policy')">《隐私权政策》</font>
					</view>
				</view>
			</view>
		</view>
	</q-popup>
</template>

<script>
	import { mapMutations } from 'vuex'
	export default {
		name: 'LoginPopup',
		data() {
			return {
				show: false
			}
		},
		methods: {
			...mapMutations(['setLogin', 'setUserInfo','setContact', 'setTodayIsSign']),
			open() {
				this.show = true;
			},
			close() {
				this.show = false;
			},
			login() {
				
				uni.showLoading({
					mask: true,
					title: '登录中'
				});
				
				uni.setStorageSync("token", "sadadadadsadadadadasdasdadsasd");
				this.getUserCenter();
				this.setLogin(true);
				this.$emit('yes');
				uni.hideLoading();
				this.close();
			},
			async getUserCenter() {
				let res = await this.$api('center')
				this.setUserInfo(res.data.userInfo);
				this.setContact(res.data.contact);
				this.setTodayIsSign(res.data.todayIsSign);
				uni.setStorageSync("userInfo", res.data.userInfo);
				uni.setStorageSync("contact", res.data.contact);
			},
			getLoginCode() {
				return new Promise((resolve, reject) => {
					uni.login({
						provider: 'weixin',
						success: function(loginRes) {
							resolve(loginRes.code);
						}
					});
				});
			},
			getUserProfile() {
				return new Promise((resolve, reject) => {
					uni.getUserProfile({
						lang: 'zh_CN',
						desc: '用于完善会员资料', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
						success: res => {
							resolve(res.userInfo);
						}
					});
				});
			},
			jump(url) {
				uni.navigateTo({url:url})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.popup-content {
		background-color: #FFFFFF;
		border-radius: 24rpx 24rpx 0 0;
		height: 50vh;
		padding: 50rpx 40rpx;
	}
	
	.close_btn {
		width: 40rpx;
		height: 40rpx;
	}
</style>
